package mysql

import (
	"jin-quan-dev/jinrpc/jinrpc"

	"gorm.io/gorm"
)

type Form struct {
	gorm.Model
	Title string `gorm:"type:varchar(30)"`
	Area  string `gorm:"type:varchar(30)"` //地区
}

func (f *Form) FormAdd(db *gorm.DB) error {
	return db.Debug().Create(f).Error
}

//func (f *Form) FormList(db *gorm.DB, in *jinrpc.ListRequest) ([]*jinrpc.ListRequest, error) {
//	var list []*jinrpc.FormList
//	err2 := db.Debug().Model(f).Select("forms.id as form_id", "title", "area").Find(list).Error
//	return nil, err2
//}

func FormList(db *gorm.DB, in *jinrpc.ListRequest) ([]*jinrpc.FormList, error) {
	var list []*jinrpc.FormList
	err2 := db.Debug().Model(&Form{}).Select("forms.id as form_id", "title", "area").
		Scopes(Paginate(int(in.Page), int(in.Size))).Find(list).Error
	return nil, err2
}
